﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using RaiderManagerBackend;

namespace RaiderManager.EditWindows
{
    /// <summary>
    /// Interaction logic for EditPlayer.xaml
    /// </summary>
    public partial class AddEditPlayerWindow : Window
    {
        private Player p;
        private bool newPlayer = false;
        public AddEditPlayerWindow()
        {
            InitializeComponent();

            p = new Player();
            newPlayer = true;
            this.PlayerGrid.DataContext = p;
        }

        public AddEditPlayerWindow(Player editPlayer)
        {
            InitializeComponent();

            p = editPlayer;

            this.PlayerGrid.DataContext = p;
        }

        private void cancelButton_Click(object sender, RoutedEventArgs e)
        {
            
            MessageBoxResult result = MessageBox.Show("Canceling will lose any edits you have made to the current player.", "Cancel Editing?", MessageBoxButton.OKCancel);
            if (result.Equals(MessageBoxResult.Cancel))
                return;
            else if (newPlayer) //null the new player if they clicked cancel so it doesn't get added to the players list.
                p = null;
            this.Close();
        }

        private void savePlayerButton_Click(object sender, RoutedEventArgs e)
        {
            p.SavePlayer();
            this.Close();
        }

        /// <summary>
        /// overriding the base showdialog so it returns a player. Interesting?
        /// </summary>
        /// <returns></returns>
        new public Player ShowDialog()
        {
            base.ShowDialog();
            return p;
        }
    }
}
